#!/bin/bash

#统计被百度链接的qId的次数

fromDate="20120201"
toDate="20120430"

#首先获取文件列表，然后针对每个Id建立词典，并将所有的统计计数加起来

count_dir="/data/link_analyse/access_count"
file_num=0
fileNameStr=""
for file in `ls $count_dir`
do
    tmpStr=${file#*_}
    dateStr=${tmpStr%%_*}
    if  [ $dateStr -ge $fromDate ] && [ $dateStr -le $toDate ] 
    then
        fileNameStr=$fileNameStr" "$count_dir"/"$file
    fi
    ((++file_num))
#echo -e "It is the "$file_num"th file. The file name is "$file"."
done
#echo $fileNameStr

awk '{
    if ($2 in retStat) {
        retStat[$2] += $1;
    }
    else { 
        retStat[$2] = $1;
    }
}
END {
    for (qId in retStat) {
        print qId, retStat[qId];
    }
}' $fileNameStr
